package net.goutalk.glcs.module.erpModel.caseErpSupplier.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import net.goutalk.glcs.common.constant.GlobalConstant;
import net.goutalk.glcs.common.enums.YesOrNoEnum;
import net.goutalk.glcs.common.page.PageOutput;
import net.goutalk.glcs.common.utils.RedisUtil;
import net.goutalk.glcs.common.utils.VoToColumnUtil;
import net.goutalk.glcs.module.erpModel.caseErpLog.entity.CaseErpLog;
import net.goutalk.glcs.module.erpModel.caseErpLog.service.ICaseErpLogService;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.dto.*;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.entity.CaseErpSupplier;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.entity.CaseErpSupplierFormal;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.entity.CaseErpSupplierRisk;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.mapper.CaseErpSupplierFormalMapper;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.mapper.CaseErpSupplierMapper;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.service.ICaseErpSupplierRiskService;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.service.ICaseErpSupplierService;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.vo.*;
import net.goutalk.glcs.module.organization.entity.User;
import net.goutalk.glcs.module.system.entity.DictionaryDetail;
import net.goutalk.glcs.module.system.service.IDictionarydetailService;
import net.goutalk.glcs.module.workflow.utils.WorkFlowUtil;
import lombok.AllArgsConstructor;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.dto.*;
import net.goutalk.glcs.module.erpModel.caseErpSupplier.vo.*;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 供应商信息【case_erp_supplier】 服务实现类
 * </p>
 *
 * @author hnyyzy
 * @since 2023-06-25
 */
@Service
@AllArgsConstructor
public class CaseErpSupplierServiceImpl extends MPJBaseServiceImpl<CaseErpSupplierMapper, CaseErpSupplier> implements ICaseErpSupplierService {
    private final ICaseErpLogService caseErpLogService;

    private final IDictionarydetailService dictionarydetailService;

    private final ICaseErpSupplierRiskService caseErpSupplierRiskService;

    private final CaseErpSupplierFormalMapper caseErpSupplierFormalMapper;

    private final ObjectMapper objectMapper;

    private RedisUtil redisUtil;

    @Override
    public String getCodeNumber() {
        //数据库中查流水号
        String sys = "";
        CaseErpSupplier one = this.getOne(Wrappers.<CaseErpSupplier>query().lambda()
                        .eq(CaseErpSupplier::getIsSysNum, YesOrNoEnum.YES.getCode()).orderByDesc(CaseErpSupplier::getCreateDate)
                , false
        );
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String format = formatter.format(new Date());
        String s = format.replaceAll("-", "");
        String system = "su" + s;
        if (one != null) {
            String nwfserialNumber = one.getCode();
            if (one.getIsSysNum().equals(YesOrNoEnum.YES.getCode())) {
                String substring = nwfserialNumber.substring(10);
                Integer integer = Integer.valueOf(substring);
                integer += 1;
                String format1 = String.format("%05d", integer);
                sys = system + format1;
            }
        } else {
            return system + "00001";
        }
        return sys;
    }

    @Override
    public PageOutput<CaseErpSupplierPageVo> getPageList(CaseErpSupplierPageDto dto) {
        if (ObjectUtil.isNotNull(dto.getStartTime()) && ObjectUtil.isNotNull(dto.getEndTime())) {
            dto.setStartTime(WorkFlowUtil.getStartOfDay(dto.getStartTime()));
            dto.setEndTime(WorkFlowUtil.getEndOfDay(dto.getEndTime()));
        }
        List<CaseErpSupplierPageVo> result = new ArrayList<>();
        List<CaseErpSupplier> list = new ArrayList<>();

        if (dto.getState() == 0) {//潜在供应商
            List<CaseErpSupplierRisk> caseErpSupplierRiskList = caseErpSupplierRiskService.list();
            list = this.list(Wrappers.lambdaQuery(CaseErpSupplier.class)
                    .eq(CaseErpSupplier::getState, 0)
                            .orderByDesc(CaseErpSupplier::getCreateDate)
                    .like(StrUtil.isNotBlank(dto.getName()), CaseErpSupplier::getName, dto.getName())
                    .like(StrUtil.isNotBlank(dto.getType()), CaseErpSupplier::getSupplierType, dto.getType())
                    .between(ObjectUtil.isNotNull(dto.getStartTime()) && ObjectUtil.isNotNull(dto.getEndTime())
                            , CaseErpSupplier::getCreateDate, dto.getStartTime(), dto.getEndTime())
                    .select(CaseErpSupplier.class, x -> VoToColumnUtil.fieldsToColumns(CaseErpSupplierPageVo.class).contains(x.getProperty())));
            if (ObjectUtil.isNotEmpty(dto.getFinalState())) {
                if (dto.getFinalState().equals(1676831983363616770L)) {//优秀
                    List<Long> collect = caseErpSupplierRiskList.stream().filter(x -> x.getFinalState().equals(1676831983363616770L)).map(CaseErpSupplierRisk::getSupplierId).collect(Collectors.toList());
                    list = list.stream().filter(x -> collect.contains(x.getId())).collect(Collectors.toList());
                } else if (dto.getFinalState().equals(1676832056248037377L)) {//良好
                    List<Long> collect = caseErpSupplierRiskList.stream().filter(x -> x.getFinalState().equals(1676832056248037377L)).map(CaseErpSupplierRisk::getSupplierId).collect(Collectors.toList());
                    list = list.stream().filter(x -> collect.contains(x.getId())).collect(Collectors.toList());
                } else if (dto.getFinalState().equals(1676832163915821058L)) {//及格
                    List<Long> collect = caseErpSupplierRiskList.stream().filter(x -> x.getFinalState().equals(1676832163915821058L)).map(CaseErpSupplierRisk::getSupplierId).collect(Collectors.toList());
                    list = list.stream().filter(x -> collect.contains(x.getId())).collect(Collectors.toList());
                } else if (dto.getFinalState().equals(1676832225265905666L)) {//不及格
                    List<Long> collect = caseErpSupplierRiskList.stream().filter(x -> x.getFinalState().equals(1676832225265905666L)).map(CaseErpSupplierRisk::getSupplierId).collect(Collectors.toList());
                    list = list.stream().filter(x -> collect.contains(x.getId())).collect(Collectors.toList());
                } else {//未评估的
                    list = list.stream().filter(x -> x.getAssessState().equals(YesOrNoEnum.NO.getCode())).collect(Collectors.toList());
                }
            }
            result = BeanUtil.copyToList(list, CaseErpSupplierPageVo.class);
            for (CaseErpSupplierPageVo caseErpSupplierPageVo : result) {
                if (caseErpSupplierPageVo.getAssessState() == YesOrNoEnum.YES.getCode()){
                    caseErpSupplierPageVo.setAssessStateName("已评估");
                }else {
                    caseErpSupplierPageVo.setAssessStateName("未评估");
                }

            }
        }
        if (dto.getState() == 1) {//正式供应商
            //如果年审状态
            List<CaseErpSupplier> caseErpSupplierList = this.list(Wrappers.lambdaQuery(CaseErpSupplier.class)
                    .orderByDesc(CaseErpSupplier::getCreateDate)
                    .eq(CaseErpSupplier::getState, 1));

            if (CollectionUtil.isNotEmpty(caseErpSupplierList)) {
                List<Long> supplierIdList = caseErpSupplierList.stream().map(x -> x.getId()).collect(Collectors.toList());
                //获取风险评估中年审的数据。
                List<CaseErpSupplierRisk> riskList = caseErpSupplierRiskService.list(Wrappers.<CaseErpSupplierRisk>query().lambda()
                        .eq(CaseErpSupplierRisk::getEnabledMark, 1).eq(CaseErpSupplierRisk::getType, 1)
                        .in(CaseErpSupplierRisk::getSupplierId, supplierIdList)
                        .orderByDesc(CaseErpSupplierRisk::getCreateDate));
                //转正申请的数据
                List<CaseErpSupplierFormal> formalList = caseErpSupplierFormalMapper.selectList(Wrappers.<CaseErpSupplierFormal>query().lambda()
                        .in(CaseErpSupplierFormal::getSupplierId, supplierIdList)
                        .eq(CaseErpSupplierFormal::getEnabledMark, 1));
                //需要更新年审状态的数据
                List<CaseErpSupplier> updatedSupplierList = new ArrayList<>();
                for (CaseErpSupplier supplier : caseErpSupplierList) {
                    //获取年审状态
                    Integer formalState = supplier.getFormalState();
                    if (formalState == null || formalState == 0) {
                        continue;
                    }
                    if (supplier.getRecoverTime() != null && supplier.getRecoverTime().plusYears(1).isBefore(LocalDateTime.now())) {
                        continue;
                    }
                    boolean isReview = false;
                    for (CaseErpSupplierRisk risk : riskList) {
                        if (ObjectUtil.equals(supplier.getId(), risk.getSupplierId())) {
                            //如果风险评估的数据和当前时间比较，大于一年，就设置年审状态为未年审。
                            if (risk.getCreateDate().plusYears(1).isBefore(LocalDateTime.now())) {
                                CaseErpSupplier updatedSupplier = new CaseErpSupplier();
                                updatedSupplier.setId(supplier.getId());
                                updatedSupplier.setFormalState(0);
                                updatedSupplierList.add(updatedSupplier);
                            }
                            isReview = true;
                            break;
                        }
                    }
                    if (!isReview) {
                        for (CaseErpSupplierFormal formal : formalList) {
                            if (ObjectUtil.equals(supplier.getId(), formal.getSupplierId())) {
                                //如果转正申请的时间和当前时间比较，大于一年，就设置年审状态为未年审。
                                if (formal.getCreateDate().plusYears(1).isBefore(LocalDateTime.now())) {
                                    CaseErpSupplier updatedSupplier = new CaseErpSupplier();
                                    updatedSupplier.setId(supplier.getId());
                                    updatedSupplier.setFormalState(0);
                                    updatedSupplierList.add(updatedSupplier);
                                    break;
                                }
                            }
                        }
                    }
                }
                if (CollectionUtil.isNotEmpty(updatedSupplierList)) {
                    this.updateBatchById(updatedSupplierList);
                }
            }
            list = this.list(Wrappers.lambdaQuery(CaseErpSupplier.class)
                    .eq(CaseErpSupplier::getState, 1)
                    .orderByDesc(CaseErpSupplier::getCreateDate)
                    .like(StrUtil.isNotBlank(dto.getName()), CaseErpSupplier::getName, dto.getName())
                    .like(StrUtil.isNotBlank(dto.getType()), CaseErpSupplier::getSupplierType, dto.getType())
                    .select(CaseErpSupplier.class, x -> VoToColumnUtil.fieldsToColumns(CaseErpSupplierPageVo.class).contains(x.getProperty())));
            if (ObjectUtil.isNotEmpty(dto.getFormalState())){
                //年审状态搜索
                if (dto.getFormalState().equals(1678217430304202754L)){//未年审,字典id
                    list = list.stream().filter(x->x.getFormalState().equals(0)).collect(Collectors.toList());
                }else if (dto.getFormalState().equals(1678217531852496897L)){//已年审
                    list = list.stream().filter(x->x.getFormalState().equals(3)).collect(Collectors.toList());
                }
            }
            result = BeanUtil.copyToList(list, CaseErpSupplierPageVo.class);
        }
        if (dto.getState() == 2) {//淘汰供应商
            list = this.list(Wrappers.lambdaQuery(CaseErpSupplier.class)
                    .eq(CaseErpSupplier::getState, 2)
                    .orderByDesc(CaseErpSupplier::getCreateDate)
                    .like(StrUtil.isNotBlank(dto.getName()), CaseErpSupplier::getName, dto.getName())
                    .like(StrUtil.isNotBlank(dto.getType()), CaseErpSupplier::getSupplierType, dto.getType())
                    .select(CaseErpSupplier.class, x -> VoToColumnUtil.fieldsToColumns(CaseErpSupplierPageVo.class).contains(x.getProperty())));
            result = BeanUtil.copyToList(list, CaseErpSupplierPageVo.class);
        }
        PageOutput<CaseErpSupplierPageVo> output = new PageOutput<>();
        output.setCurrentPage(dto.getLimit());
        output.setPageSize(dto.getSize());
        output.setTotal(list.size());
        output.setList(result);

        return output;
    }

    @Override
    public Boolean add(AddCaseErpSupplierDto dto) throws JsonProcessingException {
        CaseErpSupplier caseErpSupplier = BeanUtil.toBean(dto, CaseErpSupplier.class);
        caseErpSupplier.setAssessState(YesOrNoEnum.NO.getCode());
        caseErpSupplier.setState(YesOrNoEnum.NO.getCode());
        caseErpSupplier.setLatentState(YesOrNoEnum.NO.getCode());
        caseErpSupplier.setFormalState(YesOrNoEnum.NO.getCode());
        boolean save = this.save(caseErpSupplier);
        if (save) {
            // 添加时间轴数据
            User user = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
            CaseErpLog log = new CaseErpLog();
            log.setKeyId(caseErpSupplier.getId());
            log.setCategoryId(4);
            SupplierTimeAxisVo timeAxisVo = new SupplierTimeAxisVo();
            timeAxisVo.setTitle("成为潜在供应商");
            timeAxisVo.setContent(new String[]{"添加人：" + user.getName()});
            timeAxisVo.setTime(LocalDateTime.now());
            log.setExecuteResultJson(objectMapper.writeValueAsString(timeAxisVo));
            caseErpLogService.save(log);
        }
        return true;
    }

    @Override
    public Boolean outSupplier(SupplierOutDto dto) throws JsonProcessingException {
        CaseErpSupplier supplier = BeanUtil.toBean(dto, CaseErpSupplier.class);
        supplier.setState(2);
        boolean isSuccess = this.updateById(supplier);
        if (isSuccess) {
            // 添加时间轴数据
            User user = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
            CaseErpLog log = new CaseErpLog();
            log.setKeyId(dto.getId());
            log.setCategoryId(4);
            SupplierTimeAxisVo timeAxisVo = new SupplierTimeAxisVo();
            timeAxisVo.setTitle("被加入供应商淘汰名单");
            timeAxisVo.setTime(LocalDateTime.now());
            String[] outInfo = new String[3];
            outInfo[0] = "操作者：" + user.getName();
            //淘汰原因使用数据字典获取
            String reason = dictionarydetailService.getById(Long.valueOf(dto.getOutReason())).getName();
            outInfo[1] = "淘汰原因：" + reason;
            outInfo[2] = "淘汰说明：" + dto.getOutRemark();
            timeAxisVo.setContent(outInfo);
            log.setExecuteResultJson(objectMapper.writeValueAsString(timeAxisVo));
            caseErpLogService.save(log);
        }
        return true;
    }

    @Override
    public Boolean recoverSupplier(SupplierRecoverDto dto) throws JsonProcessingException {
        CaseErpSupplier supplier = BeanUtil.toBean(dto, CaseErpSupplier.class);
        supplier.setState(1);
        supplier.setRecoverTime(LocalDateTime.now());
        boolean isSuccess = this.updateById(supplier);
        if (isSuccess) {
            // 添加时间轴数据
            CaseErpLog log = new CaseErpLog();
            log.setKeyId(dto.getId());
            log.setCategoryId(4);
            SupplierTimeAxisVo timeAxisVo = new SupplierTimeAxisVo();
            timeAxisVo.setTitle("恢复为正式供应商");
            timeAxisVo.setTime(LocalDateTime.now());
            String[] outInfo = new String[2];
            User user = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
            outInfo[0] = "操作者：" + user.getName();
            outInfo[1] = "恢复理由：" + dto.getRecoverReason();
            timeAxisVo.setContent(outInfo);
            log.setExecuteResultJson(objectMapper.writeValueAsString(timeAxisVo));
            caseErpLogService.save(log);
        }
        return true;
    }

    @Override
    public List<SupplierTypeChartDataVo> getSupplierType() {
        //获取所有的供应商类型
        List<DictionaryDetail> dictionaryDetailList = dictionarydetailService.list(Wrappers.<DictionaryDetail>query().lambda().eq(DictionaryDetail::getItemId, 1676483934342787074L));
        //获取供应商数据，拿到type值
        List<CaseErpSupplier> caseErpSupplierList = this.list();
        List<SupplierTypeChartDataVo> result = new ArrayList<>();
        for (DictionaryDetail dictionaryDetail : dictionaryDetailList) {
            SupplierTypeChartDataVo supplierTypeChartDataVo = new SupplierTypeChartDataVo();
            //名称
            supplierTypeChartDataVo.setName(dictionaryDetail.getName());
            int value = 0;
            if (ObjectUtil.isNotEmpty(dictionaryDetail.getId())) {
                List<CaseErpSupplier> collect = caseErpSupplierList.stream().filter(x -> x.getSupplierType().contains(dictionaryDetail.getId().toString())).collect(Collectors.toList());
                if (ObjectUtil.isNotEmpty(collect)) {
                    value = collect.size();
                }
            }
            supplierTypeChartDataVo.setValue(value);
            result.add(supplierTypeChartDataVo);
        }
        return result;
    }

    @Override
    public CaseErpSupplierInfoVo info(CaseErpSupplier caseErpSupplier) {
        CaseErpSupplierInfoVo caseErpSupplierInfoVo = BeanUtil.toBean(caseErpSupplier, CaseErpSupplierInfoVo.class);
        if (caseErpSupplier.getIsSysNum() == YesOrNoEnum.YES.getCode()) {
            caseErpSupplierInfoVo.setIsSysNumBoolean(true);
        } else {
            caseErpSupplierInfoVo.setIsSysNumBoolean(false);
        }
        List<User> userList = redisUtil.get(GlobalConstant.USER_CACHE_KEY, new TypeReference<List<User>>() {
        });
        String name = userList.stream().filter(x -> x.getId().equals(caseErpSupplier.getCreateUserId())).findFirst().orElse(new User()).getName();
        caseErpSupplierInfoVo.setCreateUserName(name);
        //获取所有的供应商类型
        List<DictionaryDetail> dictionaryDetailList = dictionarydetailService.list(Wrappers.<DictionaryDetail>query().lambda().eq(DictionaryDetail::getItemId, 1676483934342787074L));
        if (StrUtil.isNotBlank(caseErpSupplier.getSupplierType())) {
            List<String> split = StrUtil.split(caseErpSupplier.getSupplierType(), StringPool.COMMA);
            String typeName = StringPool.EMPTY;
            for (String s : split) {
                DictionaryDetail dictionaryDetail = dictionaryDetailList.stream().filter(x -> x.getId().toString().equals(s)).findFirst().orElse(new DictionaryDetail());
                if (StrUtil.isNotBlank(dictionaryDetail.getName())) {
                    if (StrUtil.isNotBlank(typeName)) {
                        typeName = typeName + "、" + dictionaryDetail.getName();
                    } else {
                        typeName = dictionaryDetail.getName();
                    }
                }
            }
            caseErpSupplierInfoVo.setTypeName(typeName);
        }

        return caseErpSupplierInfoVo;
    }

    @Override
    public List<SupplierRiskVo> risk() {
        List<SupplierRiskVo> supplierRiskVoList = new ArrayList<>();
        //获取潜在供应商信息
        List<CaseErpSupplier> caseErpSupplierList = this.list();
        List<Long> supplierIds = caseErpSupplierList.stream().filter(x -> ObjectUtil.isNotEmpty(x.getState()) && x.getState().equals(YesOrNoEnum.NO.getCode())).map(CaseErpSupplier::getId).collect(Collectors.toList());
        List<CaseErpSupplierRisk> caseErpSupplierRiskList = caseErpSupplierRiskService.list();
        List<CaseErpSupplierRisk> collect = caseErpSupplierRiskList.stream().filter(x -> supplierIds.contains(x.getSupplierId())).collect(Collectors.toList());
        //获取所有的风险评估类型
        List<DictionaryDetail> dictionaryDetailList = dictionarydetailService.list(Wrappers.<DictionaryDetail>query().lambda().eq(DictionaryDetail::getItemId, 1676831752869834753L));
        for (DictionaryDetail dictionaryDetail : dictionaryDetailList) {
            SupplierRiskVo supplierRiskVo = new SupplierRiskVo();
            supplierRiskVo.setName(dictionaryDetail.getName());
            int count = collect.stream().filter(x -> ObjectUtil.isNotEmpty(x.getFinalState()) && x.getFinalState().equals(dictionaryDetail.getId().toString())).collect(Collectors.toList()).size();
            supplierRiskVo.setValue(count);
            supplierRiskVoList.add(supplierRiskVo);
        }
        return supplierRiskVoList;
    }

    @Override
    public List<SupplierHistoryPriceVO> historyPrice() {
        List<SupplierHistoryPriceVO> list = new ArrayList<>();
        SupplierHistoryPriceVO vo = new SupplierHistoryPriceVO();
        List<String> category = new ArrayList<>();
        List<Integer> data = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            category.add(i + 1 + "月");
            data.add(26 + i * 15);
        }
        vo.setCategory(category);
        vo.setData(data);
        vo.setKey(2);
        vo.setName("年度");
        list.add(vo);
        SupplierHistoryPriceVO vo2 = new SupplierHistoryPriceVO();
        List<String> category2 = new ArrayList<>();
        List<Integer> data2 = new ArrayList<>();
        category2.add("一季度");
        category2.add("二季度");
        category2.add("三季度");
        category2.add("四季度");
        data2.add(100);
        data2.add(200);
        data2.add(300);
        data2.add(400);
        vo2.setCategory(category2);
        vo2.setData(data2);
        vo2.setKey(1);
        vo2.setName("季度");
        list.add(vo2);
        SupplierHistoryPriceVO vo3 = new SupplierHistoryPriceVO();
        List<String> category3 = new ArrayList<>();
        List<Integer> data3 = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            category3.add(i + 1 + "日");
            data3.add(57 + i * 12);
        }
        vo3.setCategory(category3);
        vo3.setData(data3);
        vo3.setKey(0);
        vo3.setName("月度");
        list.add(vo3);
        return list;
    }

    @Override
    public Boolean addRisk(AddCaseErpSupplierRiskDto dto) throws JsonProcessingException {
        //如果type ==0,就是潜在新增
        CaseErpSupplierRisk caseErpSupplierRisk = BeanUtil.toBean(dto, CaseErpSupplierRisk.class);
        if (ObjectUtil.isNotEmpty(dto.getSupplierId())) {
            CaseErpSupplier oldSupplier = this.getById(dto.getSupplierId());
            //修改风险评估状态为已评估
            CaseErpSupplier caseErpSupplier = new CaseErpSupplier();
            if (oldSupplier.getState() == 1) {//正式供应商
                caseErpSupplier.setFormalState(3);//设置状态为年审已通过
            }
            caseErpSupplier.setId(dto.getSupplierId());
            caseErpSupplier.setAssessState(YesOrNoEnum.YES.getCode());
            this.updateById(caseErpSupplier);
        }
        boolean save = caseErpSupplierRiskService.save(caseErpSupplierRisk);
        //如果type==1，就是年审数据
        if (save) {
            // 添加时间轴数据
            CaseErpLog log = new CaseErpLog();
            log.setKeyId(dto.getSupplierId());
            log.setCategoryId(4);
            SupplierTimeAxisVo timeAxisVo = new SupplierTimeAxisVo();
            //获取所有的供应商风险评估类型
            List<DictionaryDetail> dictionaryDetailList = dictionarydetailService.list(Wrappers.<DictionaryDetail>query().lambda().eq(DictionaryDetail::getItemId, 1676831752869834753L));
            Map<String, String> riskStateMap = new HashMap<>(dictionaryDetailList.size());
            for (DictionaryDetail dictionaryDetail : dictionaryDetailList) {
                riskStateMap.put(dictionaryDetail.getId().toString(), dictionaryDetail.getName());
            }
            String title = StringPool.EMPTY;
            String content = StringPool.EMPTY;
            if (dto.getType() != null && dto.getType() == 1) {
                // 年审
                title = "完成" + LocalDateTime.now().getYear() + "供应商年审-";
                timeAxisVo.setFormalId(caseErpSupplierRisk.getId().toString());
                content = "最终审批人：";
            } else {
                // 风险评估
                content = "评估人：";
                title = "完成风险评估-";
            }
            timeAxisVo.setTitle(title + riskStateMap.get(dto.getFinalState().toString()));
            User user = StpUtil.getTokenSession().get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
            timeAxisVo.setContent(new String[]{content + user.getName()});
            timeAxisVo.setTime(LocalDateTime.now());
            log.setExecuteResultJson(objectMapper.writeValueAsString(timeAxisVo));
            caseErpLogService.save(log);
        }
        return true;
    }

}
